package com.goomba.demo.producer;


import com.goomba.demo.contants.Commons;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

/**
 * 有时候我们不需要返回值。我们只要发送即可。这个时候就可以使用单向队列
 */
public class OnewayProducer {

    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("producer_group1");

        producer.setNamesrvAddr(Commons.nameSrvAddr);

        producer.start();

        for (int i = 0; i < 30; i++) {
            Message message = new Message("oneWay", "tag1", ("Hello OneWay " + i).getBytes(StandardCharsets.UTF_8));
            producer.sendOneway(message);
        }

        producer.shutdown();
    }
}
